package hash;

import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.EtchedBorder;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Help extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private final JPanel contentPanel = new JPanel();
	private JTextPane textPane;
	private JButton cancelButton;

	
	/**
	 * Create the Help Dialog.
	 */
	public Help()
	{
		setTitle("Help");
		setBounds(100, 100, 450, 300);
		setResizable(false);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BorderLayout(0, 0));
		{
			JScrollPane scrollPane = new JScrollPane();
			scrollPane.setViewportBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
			scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			contentPanel.add(scrollPane, BorderLayout.CENTER);
			{			    
				textPane = new JTextPane();				
				setFormat(textPane);
				scrollPane.setViewportView(textPane);				
			}
		}
		{
			JPanel buttonPane = new JPanel();
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				cancelButton = new JButton("OK");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0)
					{						
						Help.this.dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
			}
			GroupLayout gl_buttonPane = new GroupLayout(buttonPane);
			gl_buttonPane.setHorizontalGroup(
				gl_buttonPane.createParallelGroup(Alignment.LEADING)
					.addGroup(Alignment.TRAILING, gl_buttonPane.createSequentialGroup()
						.addContainerGap(352, Short.MAX_VALUE)
						.addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, 84, GroupLayout.PREFERRED_SIZE)
						.addContainerGap())
			);
			gl_buttonPane.setVerticalGroup(
				gl_buttonPane.createParallelGroup(Alignment.LEADING)
					.addGroup(Alignment.TRAILING, gl_buttonPane.createSequentialGroup()
						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(cancelButton)
						.addContainerGap())
			);
			buttonPane.setLayout(gl_buttonPane);
		}
	}
	
	
	/**
	 * Formats Help Content Documentation.
	 * Need to Clean this up a little better then it is.
	 * <p>
	 * @param textPane - Help COntent Text Pane
	 */
	void setFormat(JTextPane textPane)
	{
		SimpleAttributeSet boldSet = new SimpleAttributeSet();
	    StyleConstants.setBold(boldSet, true);
	    StyleConstants.setFontSize(boldSet,18);
	    
	    SimpleAttributeSet colorSet = new SimpleAttributeSet();
	    StyleConstants.setForeground(colorSet, Color.blue);
	    StyleConstants.setFontSize(colorSet,14);
	    
	    SimpleAttributeSet normalSet = new SimpleAttributeSet();
	    StyleConstants.setFontSize(normalSet,12);
	    
	    Document doc = textPane.getStyledDocument();
	    
	    try
	    {	    	
	    	doc.insertString(doc.getLength(), "Help Content:", boldSet);
	    	StyleConstants.setFontSize(boldSet,16);
	    	
	    	doc.insertString(doc.getLength(), "\n\nSelect:", boldSet);
	    	doc.insertString(doc.getLength(), "\nFile to either compare or digest, " + 
	    			"the file name will\nthen be entered into file field.\n\n", normalSet);

	    	doc.insertString(doc.getLength(), "Mode:", boldSet);	    
	    	doc.insertString(doc.getLength(), "\nSet mode to either digest the file or compare checksums.\n", normalSet);

	    	doc.insertString(doc.getLength(), "   Compare Mode:", colorSet);
	    	doc.insertString(doc.getLength(), "\n      User must enter string checksum to compare to files.\n", normalSet);

	    	doc.insertString(doc.getLength(), "   Digest Mode:", colorSet);
	    	doc.insertString(doc.getLength(), "\n      User Selects file to calculate checksum of.\n\n", normalSet);

	    	doc.insertString(doc.getLength(), "Clear:", boldSet);
	    	doc.insertString(doc.getLength(), "\nClears all fields.\n\n", normalSet);

	    	doc.insertString(doc.getLength(), "Hash:", boldSet);
	    	doc.insertString(doc.getLength(), "\nCalculates and displays checksums when in digest mode or\n"+
	    			"compares and marks checkbox of checksums that matches\nuser defined strings when in compare mode." +
	    			"Progress bar\nwill display while application is calculating checksums.\n\n", normalSet);
	    	
	    	doc.insertString(doc.getLength(), "Save As:", boldSet);
	    	doc.insertString(doc.getLength(), "\nSaves checksums to file.\n\n", normalSet);
	    	
	    	// TODO: Add Load Checksum
		}
	    catch (BadLocationException e) { e.printStackTrace(); }	
	}
}
